/**
 * 功能描述
 */

define(function (require, exports, module) {
    module.exports = {
    		total : function(widget,data,datas){
				
				var dats = [];
				var returnView = {};
				var roomTotal = 0; //住宿费合计
				var foodTotal = 0; //餐饮费合计
				var trafficTotal = 0; //大交通往返费合计
				var otherTotal = 0; //其他费用合计
				var allTotal = 0; //费用总金额
				var depositTotal = 0; //预收款合计
				var deductionChargesTotal = 0; //权证抵扣合计
				var receivableTotal = 0;//应收金额合计
				var receiptsTotal = 0;//实收金额合计
				for(var i=0;i<data.length;i++){
					var items = data[i].checkOutSettlement;
					var remak = items.remak;
					var bedSubsidyUnit = items.bedSubsidyUnit;
					for(var k in items){
						if(items[k]){
							items[k] = Number(items[k])
						}else{
							items[k] = 0
						}
					}
					items.remak = remak;
					items.bedSubsidyUnit = bedSubsidyUnit;
				}
				for(var m=0;m<data.length;m++){
					var cItem =  data[m].checkOutSettlement;
					if(cItem){
						roomTotal += cItem.room;
						foodTotal += cItem.food + cItem.foodOther;
						trafficTotal += cItem.traffic;
						//其他费用合计=∑水费+水费其他+电费+电费其他+康乐费+康乐费其他+护理费+物业费+节假日费用+接送往返费+管理费+其他 ；
						otherTotal += cItem.coldWater + cItem.hotWater + cItem.telephone + cItem.waterOther
							+ cItem.electric +  cItem.electricOther + data[m].damagesConsumption + data[m].roomConsumption
							+ cItem.health + cItem.healthOther + cItem.nurse + cItem.property + cItem.holiday
							+ cItem.pickUp + cItem.manager + cItem.other;
						if(data[m].payable){
							depositTotal += data[m].payable;
						}
						deductionChargesTotal += cItem.bedSubsidy + cItem.expense + cItem.coupon;
					}
				}
								
				allTotal = roomTotal + foodTotal + trafficTotal + otherTotal;
				receivableTotal = allTotal - deductionChargesTotal - depositTotal;
				returnView.roomTotal = roomTotal;
				returnView.foodTotal = foodTotal;
				returnView.trafficTotal = trafficTotal;
				returnView.otherTotal = otherTotal;
				returnView.allTotal = allTotal;//费用总金额
				returnView.depositTotal = depositTotal;//预收款合计
				returnView.deductionChargesTotal = deductionChargesTotal;//权证抵扣合计
				returnView.receivableTotal = receivableTotal;//应收金额合计
				
				if(datas.balance == null){
					returnView.receiptsTotal=receivableTotal;
				}else{
					returnView.receiptsTotal=datas.balance;
					widget.set("receiptsTotal", parseFloat(datas.balance));
				}
				
				if(datas.paymentMethods!=null){
					returnView.paymentMethod=datas.paymentMethods;
					widget.set("paymentMethod", datas.paymentMethods);
				}else{
					returnView.paymentMethod=[{key:"Cash",value:"现金"}];
				}
				if(datas.description != "" ){
					returnView.description = datas.description;
					widget.set("description", datas.description);
				}
				dats.push(returnView);
				widget.get("totalGrid").setData([]);
				widget.get("totalGrid").setData(dats);
			}
    };
});
